using UnityEngine;
using System.Collections.Generic;
using System.Collections;

public class Globals : Singleton<Globals> {
	
	public SceneLoadManager MSceneLoadManager = null;
	
	/// <summary>
	/// Init this instance.
	/// </summary>
	public void Init(){
		GameObject go = GameObject.Find("Start");
		if(go != null){
			MSceneLoadManager = go.GetComponent<SceneLoadManager>();
		}
	}
	
	/// <summary>
	/// The m list config.
	/// </summary>
	protected Dictionary<string, ConfigBase> mListConfigs = new Dictionary<string, ConfigBase>();
	
	/// <summary>
	/// Gets the config.
	/// </summary>
	/// <returns>
	/// The config.
	/// </returns>
	/// <typeparam name='T'>
	/// The 1st type parameter.
	/// </typeparam>
	public T GetConfig<T>()where T : ConfigBase {
		System.Type t = typeof(T);
		
		if (!mListConfigs.ContainsKey(t.Name)){
			
			T config = System.Activator.CreateInstance<T>();
			mListConfigs[t.Name] = config;
						
			TextAsset textAsset = Resources.Load("Config/" + t.Name) as TextAsset;
			LitJson.JsonData jd = LitJson.JsonMapper.ToObject(textAsset.text);
			
			config.LoadJsonData(jd);
			
			return config;
		}

		return (T)(mListConfigs[t.Name]);
		
	}	
}
